package com.ebt.m.customer.util;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import com.ebt.m.commons.buscomponent.permission.RxPermissions;

/**
 * Created by Rick.Wang on 2016/12/20.
 */

public class PhoneUtil {

    public static void callPhone(Activity context, String phoneNumber) {
        callPhone(context, Uri.parse("tel:" + phoneNumber));
    }

    public static void callPhone(Activity context, Uri url) {
        RxPermissions rxPermissions = new RxPermissions(context);
        rxPermissions.request(Manifest.permission.CALL_PHONE,
                Manifest.permission.PROCESS_OUTGOING_CALLS,
                Manifest.permission.READ_CALL_LOG
        )
                .subscribe(granted -> {
                    if (granted) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_DIAL);
                        intent.setData(url);
                        context.startActivity(intent);
                    } else {
                        com.ebt.m.commons.utils.ToastUtil.show(context, "请允许相关权限，才能拨打电话并生成更准确的客户报告");
                    }
                });
    }

}
